package lol.clann.minecraft.springboot.plugin.bukkit.impl;

import lol.clann.minecraft.springboot.api.annotation.compatibility.CompatibilityChecked;
import lol.clann.minecraft.springboot.api.bukkit.model.BoundingBox;
import lol.clann.minecraft.springboot.api.bukkit.utils.BoundingBoxUtils;
import lol.clann.minecraft.springboot.bukkit.utils.BukkitUtils;
import net.minecraft.server.v1_12_R1.AxisAlignedBB;
import org.springframework.stereotype.Service;

/**
 *
 * @author pyz
 * @date 2019/6/9 2:26 PM
 */
@Service
@CompatibilityChecked
public class BoundingBoxUtilsImpl_all implements BoundingBoxUtils {
   
    @Override
    public BoundingBox fromNMS(Object nmsAxisAlignedBB) {
        if (BukkitUtils.getBukkitVersionNumber() < 11300) {
            AxisAlignedBB axisAlignedBB = (AxisAlignedBB) nmsAxisAlignedBB;
            return new BoundingBox(
                    axisAlignedBB.a,
                    axisAlignedBB.b,
                    axisAlignedBB.c,
                    axisAlignedBB.d,
                    axisAlignedBB.e,
                    axisAlignedBB.f);
        } else {
            net.minecraft.server.v1_13_R2.AxisAlignedBB axisAlignedBB = (net.minecraft.server.v1_13_R2.AxisAlignedBB) nmsAxisAlignedBB;
            return new BoundingBox(
                    axisAlignedBB.minX,
                    axisAlignedBB.minY,
                    axisAlignedBB.minZ,
                    axisAlignedBB.maxX,
                    axisAlignedBB.maxY,
                    axisAlignedBB.maxZ);
        }
    }

    @Override
    public <T> T toNMS(BoundingBox boundingBox) {
        if (BukkitUtils.getBukkitVersionNumber() < 10900) {
            return (T) net.minecraft.server.v1_7_R4.AxisAlignedBB.a(boundingBox.getMinX(), boundingBox.getMinY(), boundingBox.getMinZ(), boundingBox.getMaxX(), boundingBox.getMaxY(), boundingBox.getMaxZ());
        } else {
            return (T) new net.minecraft.server.v1_14_R1.AxisAlignedBB(boundingBox.getMinX(), boundingBox.getMinY(), boundingBox.getMinZ(), boundingBox.getMaxX(), boundingBox.getMaxY(), boundingBox.getMaxZ());
        }
    }

}
